# 数据采集
# 软件测试
# 抢票
import requests

# 目标url

url = 'https://www.baidu.com/'

# 构建请求头
headers = {
    # User-Agent  必选参数 ,用来模拟用户
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36'
}

# 发送请求
resp = requests.get(url, headers=headers)

# 保存响应结果
with open('file/百度.html', 'w', encoding='utf-8') as f:
    f.write(resp.content.decode())

# 保存图片
resp = requests.get('https://inews.gtimg.com/om_bt/OHyQqgC_5oi4Vm0tlH49XvJzqNBHo2Zryxx5F_be5N2cIAA/1000')

# wb 二进制的形式写入
with open('file/1.jpg', 'wb') as f:
    f.write(resp.content)
